#!/usr/local/bin/python2.5

_Copyright = "Copyright @ 2010 Michael P. Reilly. All rights reserved."

_SCM_ID = "$Id$"

import os
from kcapp.app import logging, main
from kcapp.reqhandler import HelpRequestHandler

Admin_email_address = [
    'arcege@gmail.com',
]

class IndexPage(HelpRequestHandler):
    template_name = 'index'
    def process_request(self):
        self.vars['help_url'] == ''

class HelpPage(HelpRequestHandler):
    def process_request(self, page):
        tmplfile = self.template_file(page)
        if os.path.isfile(tmplfile):
            self.template_name = page
        elif page.endswith('badpage'): 
            raise self.NotFound
        else:
            raise self.Redirect('/help/badpage?page=%s' % page)

class PathRedirectPage(HelpRequestHandler):
    """Redirect /help/foo/bar paths into /help/foo_bar paths, better SEO"""
    def process_request(self, sect1, sect2):
        raise self.PermRedirect('/help/%s_%s' % (sect1, sect2))

class BadPage(HelpRequestHandler):
    template_name = 'badpage'
    def process_request(self):
        self.vars['page'] = str(self.request.get('page'))
        logging.warn('page = %s' % repr(self.vars['page']))
        self.vars['help_url'] = ''

URL_Map = [
    ('/help', IndexPage),
    ('/help/', IndexPage),
    ('/help/badpage', BadPage),
    ('/help/(.*)/(.*)', PathRedirectPage),
    ('/help/(.*)', HelpPage),
]

if __name__ == "__main__":
    main(URL_Map)
